#include <iostream>
#include <vector>
#include <cmath>
#include <fstream>
#include <string>
#include <iomanip>  
#include <cblas.h>
#include <lapacke.h>
#include "Spline.hpp"  

// Define the function f(x) = 1 / (1 + 25 * x^2)
double f(double x) {
    return 1.0 / (1.0 + 25 * x * x);
}


int main() {
    // Define the different N values for testing
    int N = 10;
    std::vector<double> x_vals(N+1), y_vals(N+1);
        
    // Write data to a file 
    std::ofstream file1("spline_test4_PPform_complete.csv");
    for (int i = 0; i <= N; ++i) {
            x_vals[i] = -1.0 + 2.0 * i / (N);  // Evenly spaced nodes from -1 to 1
            y_vals[i] = f(x_vals[i]);
    }
    // Create the PPForm spline interpolation object
    PPForm spline1(x_vals, y_vals, "complete", 25/26.0/26.0, -25/26.0/26.0);
    
    for (double x = -1; x <= 1; x += 0.01) {
        double y = spline1.getSplineValue(x);  // 通过样条插值计算 y 值
        file1 << x << "," << y << "\n";  // 将结果写入文件
    }
    file1.close();
    BSpline spline2(x_vals, y_vals, 3,"complete", 25/26.0/26.0, -25/26.0/26.0);
    std::ofstream file2("spline_test4_BSpline_complete.csv");
    for (double x = -1; x <= 1; x += 0.01) {
        double y = spline2.getSplineValue(x);  // 通过样条插值计算 y 值
        file2 << x << "," << y << "\n";  // 将结果写入文件
    }
    file2.close();
    std::cout << "Test results are saved" << std::endl;

    return 0;
}